package com.neu.servlet.ww;

import com.neu.service.ww.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "SearchGoodsServlet",urlPatterns = "/SearchGoodsServlet.do")
public class SearchGoodsServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String text=request.getParameter("search");
        System.out.println(text);
        GoodsService goodsService=new GoodsService();
        List<Map<String,Object>> searchList=goodsService.doFindByLike(text);
        HttpSession session=request.getSession();
        if (searchList != null&&!searchList.isEmpty()) {
            session.setAttribute("searchList", searchList);
        }
        response.sendRedirect("showGoods.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
